package tp.badugi.net;

import tp.badugi.net.exceptions.IllegalCharactersException;
import tp.badugi.net.exceptions.IllegalParameterValueException;
import tp.badugi.net.exceptions.NameTakenException;
import tp.badugi.net.exceptions.NoSuchTableException;
import tp.badugi.net.exceptions.ParameterOutOfBoundsException;
import tp.badugi.net.exceptions.ServerCouldNotCompleteRequestException;
import tp.badugi.net.exceptions.TableFullException;

public interface iServerRequestListener {
	
	/**
	 * Creates a new table on the server and joins the table.
	 * @param netChannel a <@link {@link ClientNetworkingChannel} object responsible for
	 * handling the connection with the client who made the request.
	 * @param myPlayerName name chosen by the player.
	 * @param tableName name of the table - used by other players to connect.
	 * @param maxPlayers the maximum number of players that are allowed to join (<=6).
	 * @param startingChips the amount of chips that each player starts with.
	 * @param smallBlind the amount of small blind to set for the table.
	 * @param bigBlind the amount of big blind to set for the table.
	 * @return True if the table was successfully created.
	 * @throws NameTakenException if the table name is taken.
	 * @throws IllegalCharactersException if the table name or player name 
	 * contains illegal characters.
	 * @throws ParameterOutOfBoundsException if one or more table parameter is out of bounds.
	 * @throws ServerCouldNotCompleteRequestException if the server could not create a table
	 * for an unknown reason.
	 */
	public iTableRequestListener createTable(
			ServerNetworkingChannel netChannel,
			String myPlayerName, 
			String tableName, 
			int maxPlayers, 
			long startingChips, 
			long smallBlind, 
			long bigBlind
	) throws NameTakenException, 
			IllegalCharactersException, 
			IllegalParameterValueException, 
			ServerCouldNotCompleteRequestException;
	
	/**
	 * Returns a list of tables created on the server.
	 * 
	 * @return list of tables created on the server or <code>null</code> if there are no tables.
	 */
	public String[] getTableNamesList();
	
	/**
	 * Joins an existing table on the server.
	 * 
	 * @param netChannel <code>ServerNetworkingChannel</code> with an open connection to the client.
	 * @param tableName table name. Use {@link #getTableNamesList()} to retrieve table names.
	 * @param myPlayerName name chosen by the player.
	 * @return an instance of the <code>iTableRequestListener</code> interface for calling
	 * methods related to table requests from client.
	 * @throws TableFullException if the table is full.
	 * @throws IllegalCharactersException if the player name contains illegal characters.
	 * @throws ServerCouldNotCompleteRequestException if the server could not add the player
	 * for an unknown reason.
	 * @throws NameTakenException If the player name has been taken.
	 * @throws NoSuchTableException If the table does not exist.
	 */
	public iTableRequestListener joinTable(ServerNetworkingChannel netChannel, String tableName, String myPlayerName)
			throws TableFullException, IllegalCharactersException, 
			ServerCouldNotCompleteRequestException, NameTakenException, NoSuchTableException;

}
